<?php

require_once 'PHPUnit/Framework/TestCase.php';
require_once 'library/My/Csv/Import.php';
/**
 *  test case.
 */
class ImportTest extends PHPUnit_Framework_TestCase {
	
	const CSV_FILE = 'testFile.csv';
	const NOT_EXIST_CSV_FILE = 'file_doesnt_exist.csv';
	
	/** 
	 * @var My_Csv_File
	 */
	protected $_instance;
	
	/**
	 * Root path
	 * @var string
	 */
	protected $_root; 
	
	
	/**
	 * Prepares the environment before running a test.
	 */
	protected function setUp() {
		parent::setUp ();
		$this->_root = dirname(__FILE__) . '/';		
		$this->_instance = new My_Csv_Import($this->_root . self::CSV_FILE);
	}
	
	/**
	 * Cleans up the environment after running a test.
	 */
	protected function tearDown() {
		parent::tearDown ();		
	}
	
	/**
	 * Constructs the test case.
	 */
	public function __construct() {		
	}	
	
	/**
	 * @expectedException My_Csv_Exception
	 */
	public function testFileNotExist(){		
		$this->_instance->setFile(self::NOT_EXIST_CSV_FILE);
	}	
	
	/**
	 * @expectedException My_Csv_Exception
	 */
	public function testPatternIsNotSet(){		
		$this->_instance->parseToArray();
	}
	
	public function testParseToArrayMethod(){
		require_once 'library/My/Pattern.php';
		$this->_instance->setPattern(new My_Pattern('[:tit][:meno][:titza]'));
		$this->assertTrue(is_array($this->_instance->parseToArray()));
	}
	
	public function testGetFileMethod(){
		$this->assertTrue(is_array($this->_instance->getFile()));
	}
}

